import logging, string

from PySide6.QtCore import QThread, Signal
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
from osgeo import ogr
from osgeo.gdal import Driver
from osgeo.ogr import DataSource, Layer, Geometry, FeatureDefn, FieldDefn, Feature
# 驱动名称
from osgeo.osr import SpatialReference


class DriverType:
    OPEN_FILE_GDB_DERIVE = "OpenFileGDB"


if __name__ == '__main__':
    driver: Driver = ogr.GetDriverByName("OpenFileGDB")
    fileName = "F:\gis数据-本地\QNZTDLYXZ20004490.gdb"
    dataSource: DataSource = driver.Open(fileName, 0)
    layer: Layer = dataSource.GetLayerByIndex(0)
    for feature in layer:
        dataTypeFieldIndex = feature.GetFieldIndex("area")
        # 要素字段名集合

        # 图形字段
        geometry: Geometry = feature.geometry()
        m_area = (geometry.Area() / (0.0089 ** 2)) * 1e+6
        feature.SetField("area", m_area)
    dataSource.Destroy()
